﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EQual.MainModule.Documents.DetailViews
{
    /// <summary>
    /// this manages roles to Documents View
    /// </summary>
   public  class RoleDestributionPresenter
    {
       public RoleDestributionView View { get; set; }
       public RolesDialog RolesDialog;

       //DetailViews.EmployeesDestributionDialog EmployeeDialog { get; set; }

       public RoleDestributionPresenter()
       {
           View = new RoleDestributionView();
           View.presenter = this;
       }

       DataAccesLayer.Document _activeItem;
       public DataAccesLayer.Document ActiveItem
       {
           get { return _activeItem; }
           set
           {
               _activeItem = value;
               View.DisplayRoles(value);
           }
       }

      internal void DisplayRolesDialog()
      {
          RolesDialog = new RolesDialog();      
          RolesDialog.presenter = this;
          RolesDialog.Model = new DataAccesLayer.EQualDataLayerFactory().GetEmployeeAccesLayer().GetRolesDestribution(ActiveItem);
          RolesDialog.ShowDialog();
        
          View.DisplayRoles(ActiveItem);
      }


      internal void DisplayEmployeesDialog()
      {
          DestributionToEmployeePresenter employpresenter = new DestributionToEmployeePresenter();
          employpresenter.View = new DetailViews.EmployeesDistributionDialog();
          employpresenter.DisplayDocumentDestribution(ActiveItem);
          ((DetailViews.EmployeesDistributionDialog)employpresenter.View).ShowDialog();

          employpresenter.ActiveItem = ActiveItem;
      }

      internal void AddRoleToDocument(object p)
      {
          new DataAccesLayer.EQualDataLayerFactory().GetEmployeeAccesLayer().AddRoleDistribution(p as DataAccesLayer.Role, ActiveItem);
      }

      internal void RemoveRoleToDocument(object p)
      {
          new DataAccesLayer.EQualDataLayerFactory().GetEmployeeAccesLayer().RemoveRoleDistribution(p as DataAccesLayer.Role, ActiveItem);
      }
    }


    /// <summary>
    /// this is a presenter to manage an Employees To Documents View 
    /// </summary>
   public class DestributionToEmployeePresenter : Documents.DocumentsDetailViews.DocumentsDestributionPresenter
   {
       protected override void SetUpViewModel(WpfApplicationExperimental.DAOCollection<DataAccesLayer.Employee> empls)
       {
           View.Model  = empls;
       }
   }
}
